#include "SUiMetaDataReader.h"
#include <QtCore>
#include <QtGui>
#include "SDKDevice/SDevicePluginInterface.h"

SUiMetaDataReader::SUiMetaDataReader(QWidget *parent):
	QMainWindow(parent)
{
	setupUi(this);

	SGlobalMetaDataMap gmdm;

	QStringList allObjects = gmdm.allObjects();
	model_ = new QStandardItemModel(allObjects.count(), 4, this);

	

	int nbobj = allObjects.count();
	for( int r=0; r<nbobj; r++ ){ // tous les obj du gmdm

			QStandardItem *item = new QStandardItem( allObjects.value(r) );
			QList<SMetaData> allMetaDataOf = gmdm.allMetaDataOf(allObjects.value(r));

			for( int i=0; i< allMetaDataOf.count(); i++ ){
			
					QStandardItem *childC1 = new QStandardItem( allMetaDataOf.at(i).name() );
					QStandardItem *childC2 = new QStandardItem( allMetaDataOf.at(i).value().toString() );
					QStandardItem *childC3 = new QStandardItem( allMetaDataOf.at(i).unit());
					//QStandardItem *childC4 = new QStandardItem( allMetaDataOf.at(i).shortcut());

					childC1->setEditable( false );
					childC2->setEditable( false );
					childC3->setEditable( false );

					item->setChild(i,0,childC1);
					item->setChild(i,1,childC2);
					item->setChild(i,2,childC3);
					//item->setChild(i,4,childC4);
					
					
				}
					
				model_->setItem(r, 0, item);
	}

	model_->setHorizontalHeaderItem( 0, new QStandardItem( "Name" ) );
	model_->setHorizontalHeaderItem( 1, new QStandardItem( "Value" ) );
	model_->setHorizontalHeaderItem( 2, new QStandardItem( "Unit" ) );
	
	tvMetaData->setModel( model_ );

	//this->connect(model_,"dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight )","updated( const QModelIndex & topLeft, const QModelIndex & bottomRight )");
}


SUiMetaDataReader::~SUiMetaDataReader(void)
{
}

void SUiMetaDataReader::updated( const QModelIndex & topLeft, const QModelIndex & bottomRight )
{
	qDebug() << "DataCahnge : " << topLeft.column() << " " << topLeft.row();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// \fn  void SUiMainWindow::closeEvent(QCloseEvent *e)
///
/// \brief	(SLOT) When the user click on the [X] (close) button
////////////////////////////////////////////////////////////////////////////////////////////////////
void SUiMetaDataReader::closeEvent( QCloseEvent *e )
{
	this->deleteLater();
	
}
